import Vue from 'vue'
import VueRouter from 'vue-router'
import index from '../views/index.vue'
import login from '../views/login.vue'
import forgot from '../views/forgot.vue'
import register from '../views/register.vue'
Vue.use(VueRouter)

const routes = [
  // 主页
  {
    path: '/',
    name: 'index',
    component: index,
    meta: {
      index: 0,
      title: '首页',
    },
  },

  // 登录
  {
    path: '/login',
    name: 'login',
    component: login,
    meta: {
      index: 0,
      title: '登录',
    },
  },

  // 注册
  {
    path: '/register',
    name: 'register',
    component: register,
    meta: {
      index: 0,
      title: '注册',
    },
  },

  // 忘记密码
  {
    path: '/forgot',
    name: 'forgot',
    component: forgot,
    meta: {
      index: 0,
      title: '忘记密码',
    },
  },

  // 修改密码
  {
    path: '/user/password',
    name: 'password',
    component: () => import('../views/user/password.vue'),
    meta: {
      index: 0,
      title: '修改密码',
    },
  },

  // 轮播图路由
  {
    path: '/slides/table',
    name: 'slides_table',
    component: () => import('../views/slides/table.vue'),
    meta: {
      index: 0,
      title: '轮播图列表',
    },
  },
  {
    path: '/slides/view',
    name: 'slides_view',
    component: () => import('../views/slides/view.vue'),
    meta: {
      index: 0,
      title: '轮播图详情',
    },
  },
  // 文章路由
  {
    path: '/article/table',
    name: 'article_table',
    component: () => import('../views/article/table.vue'),
    meta: {
      index: 0,
      title: '文章列表',
    },
  },
  {
    path: '/article/view',
    name: 'article_view',
    component: () => import('../views/article/view.vue'),
    meta: {
      index: 0,
      title: '文章详情',
    },
  },

  // 文章分类路由
  {
    path: '/article_type/table',
    name: 'article_type_table',
    component: () => import('../views/article_type/table.vue'),
    meta: {
      index: 0,
      title: '文章分类列表',
    },
  },
  {
    path: '/article_type/view',
    name: 'article_type_view',
    component: () => import('../views/article_type/view.vue'),
    meta: {
      index: 0,
      title: '文章分类详情',
    },
  },

  // 论坛路由
  {
    path: '/forum/table',
    name: 'forum_table',
    component: () => import('../views/forum/table.vue'),
    meta: {
      index: 0,
      title: '论坛列表',
    },
  },
  {
    path: '/forum/view',
    name: 'forum_view',
    component: () => import('../views/forum/view.vue'),
    meta: {
      index: 0,
      title: '论坛详情',
    },
  },

  // 论坛分类路由
  {
    path: '/forum_type/table',
    name: 'forum_type_table',
    component: () => import('../views/forum_type/table.vue'),
    meta: {
      index: 0,
      title: '论坛分类列表',
    },
  },
  {
    path: '/forum_type/view',
    name: 'forum_type_view',
    component: () => import('../views/forum_type/view.vue'),
    meta: {
      index: 0,
      title: '论坛分类详情',
    },
  },

  // 公告路由
  {
    path: '/notice/table',
    name: 'notice_table',
    component: () => import('../views/notice/table.vue'),
    meta: {
      index: 0,
      title: '网站公告列表',
    },
  },
  {
    path: '/notice/view',
    name: 'notice_view',
    component: () => import('../views/notice/view.vue'),
    meta: {
      index: 0,
      title: '网站公告详情',
    },
  },

  // 评论路由
  {
    path: '/comment/table',
    name: 'comment_table',
    component: () => import('../views/comment/table.vue'),
    meta: {
      index: 0,
      title: '评论列表',
    },
  },
  {
    path: '/comment/view',
    name: 'comment_view',
    component: () => import('../views/comment/view.vue'),
    meta: {
      index: 0,
      title: '评论详情',
    },
  },

  // 普通用户路由
  {
    path: '/regular_users/table',
    name: 'regular_users_table',
    component: () => import('../views/regular_users/table.vue'),
    meta: {
      index: 0,
      title: '普通用户列表',
    },
  },
  {
    path: '/regular_users/view',
    name: 'regular_users_view',
    component: () => import('../views/regular_users/view.vue'),
    meta: {
      index: 0,
      title: '普通用户详情',
    },
  },
  // 商家用户路由
  {
    path: '/merchant_users/table',
    name: 'merchant_users_table',
    component: () => import('../views/merchant_users/table.vue'),
    meta: {
      index: 0,
      title: '商家用户列表',
    },
  },
  {
    path: '/merchant_users/view',
    name: 'merchant_users_view',
    component: () => import('../views/merchant_users/view.vue'),
    meta: {
      index: 0,
      title: '商家用户详情',
    },
  },
  // 景点信息路由
  {
    path: '/attraction_information/table',
    name: 'attraction_information_table',
    component: () => import('../views/attraction_information/table.vue'),
    meta: {
      index: 0,
      title: '景点信息列表',
    },
  },
  {
    path: '/attraction_information/view',
    name: 'attraction_information_view',
    component: () => import('../views/attraction_information/view.vue'),
    meta: {
      index: 0,
      title: '景点信息详情',
    },
  },
  // 门票订单路由
  {
    path: '/ticket_orders/table',
    name: 'ticket_orders_table',
    component: () => import('../views/ticket_orders/table.vue'),
    meta: {
      index: 0,
      title: '门票订单列表',
    },
  },
  {
    path: '/ticket_orders/view',
    name: 'ticket_orders_view',
    component: () => import('../views/ticket_orders/view.vue'),
    meta: {
      index: 0,
      title: '门票订单详情',
    },
  },
  // 餐厅信息路由
  {
    path: '/restaurant_information/table',
    name: 'restaurant_information_table',
    component: () => import('../views/restaurant_information/table.vue'),
    meta: {
      index: 0,
      title: '餐厅信息列表',
    },
  },
  {
    path: '/restaurant_information/view',
    name: 'restaurant_information_view',
    component: () => import('../views/restaurant_information/view.vue'),
    meta: {
      index: 0,
      title: '餐厅信息详情',
    },
  },
  // 餐厅订单路由
  {
    path: '/restaurant_orders/table',
    name: 'restaurant_orders_table',
    component: () => import('../views/restaurant_orders/table.vue'),
    meta: {
      index: 0,
      title: '餐厅订单列表',
    },
  },
  {
    path: '/restaurant_orders/view',
    name: 'restaurant_orders_view',
    component: () => import('../views/restaurant_orders/view.vue'),
    meta: {
      index: 0,
      title: '餐厅订单详情',
    },
  },
  // 酒店信息路由
  {
    path: '/hotel_information/table',
    name: 'hotel_information_table',
    component: () => import('../views/hotel_information/table.vue'),
    meta: {
      index: 0,
      title: '酒店信息列表',
    },
  },
  {
    path: '/hotel_information/view',
    name: 'hotel_information_view',
    component: () => import('../views/hotel_information/view.vue'),
    meta: {
      index: 0,
      title: '酒店信息详情',
    },
  },
  // 酒店订单路由
  {
    path: '/hotel_orders/table',
    name: 'hotel_orders_table',
    component: () => import('../views/hotel_orders/table.vue'),
    meta: {
      index: 0,
      title: '酒店订单列表',
    },
  },
  {
    path: '/hotel_orders/view',
    name: 'hotel_orders_view',
    component: () => import('../views/hotel_orders/view.vue'),
    meta: {
      index: 0,
      title: '酒店订单详情',
    },
  },
  // 民宿信息路由
  {
    path: '/homestay_information/table',
    name: 'homestay_information_table',
    component: () => import('../views/homestay_information/table.vue'),
    meta: {
      index: 0,
      title: '民宿信息列表',
    },
  },
  {
    path: '/homestay_information/view',
    name: 'homestay_information_view',
    component: () => import('../views/homestay_information/view.vue'),
    meta: {
      index: 0,
      title: '民宿信息详情',
    },
  },
  // 民宿订单路由
  {
    path: '/homestay_orders/table',
    name: 'homestay_orders_table',
    component: () => import('../views/homestay_orders/table.vue'),
    meta: {
      index: 0,
      title: '民宿订单列表',
    },
  },
  {
    path: '/homestay_orders/view',
    name: 'homestay_orders_view',
    component: () => import('../views/homestay_orders/view.vue'),
    meta: {
      index: 0,
      title: '民宿订单详情',
    },
  },

  // 用户路由
  {
    path: '/user/table',
    name: 'user_table',
    component: () => import('../views/user/table.vue'),
    meta: {
      index: 0,
      title: '用户列表',
    },
  },
  {
    path: '/user/view',
    name: 'user_view',
    component: () => import('../views/user/view.vue'),
    meta: {
      index: 0,
      title: '用户详情',
    },
  },
  {
    path: '/user/info',
    name: 'user_info',
    component: () => import('../views/user/info.vue'),
    meta: {
      index: 0,
      title: '个人信息',
    },
  },
  // 用户组路由
  {
    path: '/user_group/table',
    name: 'user_group_table',
    component: () => import('../views/user_group/table.vue'),
    meta: {
      index: 0,
      title: '用户组列表',
    },
  },
  {
    path: '/user_group/view',
    name: 'user_group_view',
    component: () => import('../views/user_group/view.vue'),
    meta: {
      index: 0,
      title: '用户组详情',
    },
  },
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes,
})

router.beforeEach((to, from, next) => {
  let token = to.query.token
  if (token) {
    $.db.set('token', token, 120)
  }
  next()
})

router.afterEach((to, from, next) => {
  let title = '乡村旅游服务平台-admin'
  document.title = title
})

export default router
